package mess;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class LeeCode_1487_2 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(getFolderNames(new String[]{"a", "a", "a", "a", "a","a","a","a","a","a","a","a"})));
        System.out.println(Arrays.toString(getFolderNames(new String[]{"kaido", "kaido(1)", "kaido", "kaido(1)"})));
    }
    private static String[] getFolderNames(String[] names) {
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            if (!map.containsKey(name)){
                //第一次出现
                map.put(name, 0);
            }else {
                //给先前记录+1
                int count = map.get(name);
                while (map.containsKey(names[i])){
                    count++;
                    names[i] = name + "(" + count + ")";
                    map.put(name, count);
                }
                //记录更改后的name
                map.put(names[i], 0);
            }
        }
        return names;
    }
}
